package com.bjsxt.comment.dao.impl.impl;

import com.bjsxt.comment.dao.OrderDao;
import com.bjsxt.livegoods.pojo.Order;
import com.mongodb.client.result.UpdateResult;
import com.netflix.discovery.converters.Auto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * @ClassName : OrderDaoImpl
 * @Description :
 * @Author : ZWZ
 * @Date: 2021/8/27 18:23
 */
@Repository
public class OrderDaoImpl implements OrderDao {

    @Autowired
    private MongoTemplate mongoTemplate;


    @Override
    public Order findById(String orderId) {
        return mongoTemplate.findById(orderId, Order.class);
    }

    @Override
    public void updateCommentState(String orderId, int commentState) {
        Query query = new Query();
        query.addCriteria(Criteria.where("orderId").is(orderId));
        Update update = Update.update("commentState", commentState);
        mongoTemplate.updateFirst(query, update, Order.class);
    }
}
